function ship_update2(timeDelta)
{
	if (leftKey.pressed)
	{
		//debug.innerHTML = "left";
		this.thrustDir += 5.0;
		if (this.thrustDir > 359.0)
			this.thrustDir = this.thrustDir - 359.0;
	}

	if (rightKey.pressed)
	{
		//debug.innerHTML = "right";
		this.thrustDir -= 5.0;
		if (this.thrustDir < 0.0)
			this.thrustDir = 359.0 + this.thrustDir;
	}
	
	if (thrustKey.pressed)
	{
		// apply acceleration to velocity
		//debug2.innerHTML = "thrust";
		this.velocityX += this.accel;
		if (this.velocityX > 1.0)
			this.velocityX = 1.0;
		//debug.innerHTML = this.velocityX;
	}

	// Use this style if you want the ship's thrust
	// to effect the direction continously.
	this.positionX += -this.velocityX * Gl_cos[this.thrustDir];
	this.positionY += -this.velocityY * Gl_sin[this.thrustDir];
	
	if (this.positionY > 94.0)
		debug3.innerHTML = "BOOM!";
	else
		debug3.innerHTML = Math.floor(this.positionX)+","+Math.floor(this.positionY);	
}

function ship_reset()
{
	this.thrustDir = 90; // Thrust starts off downwards
	
	this.positionX = 100.0;
	this.positionY = 75.0;
	
	this.velocityX = 0.0;
	this.velocityY = 0.0;
}

function ship_update(timeDelta)
{
	if (leftKey.pressed)
	{
		//debug.innerHTML = "left";
		this.thrustDir += 10.0;
		if (this.thrustDir > 359.0)
			this.thrustDir = this.thrustDir - 359.0;
	}

	if (rightKey.pressed)
	{
		//debug.innerHTML = "right";
		this.thrustDir -= 10.0;
		if (this.thrustDir < 0.0)
			this.thrustDir = 359.0 + this.thrustDir;
	}
	
	if (thrustKey.pressed)
	{
		// apply acceleration to current velocity
		//debug2.innerHTML = "thrust";
		this.velocityX += this.accel * Gl_cos[this.thrustDir];
		if (this.velocityX > 4.0)
			this.velocityX = 4.0;
		else if (this.velocityX < -4.0)
			this.velocityX = -4.0;
			
		this.velocityY += this.accel * Gl_sin[this.thrustDir];
		if (this.velocityY > 4.0)
			this.velocityY = 4.0;
		else if (this.velocityY < -4.0)
			this.velocityY = -4.0;
		//debug.innerHTML = shipVelX+","+shipVelY;
	}

	this.positionX += -this.velocityX;
	this.positionY += -this.velocityY;

	if (this.positionY > 94.0)
		debug3.innerHTML = "BOOM!";
	//else
	//	debug3.innerHTML = Math.floor(this.positionX)+","+Math.floor(this.positionY);	
}

function ship_draw()
{
	ctx.strokeStyle = "rgb(150,50,50)";
	ctx.strokeRect(Math.floor(this.positionX), Math.floor(this.positionY), 6, 6);
	
	// Draw thrust line
	ctx.strokeStyle = "rgb(200,0,0)";
	ctx.beginPath();
	var spx = this.positionX + 3;
	var spy = this.positionY + 3;
	ctx.moveTo(spx, spy);
	ctx.lineTo(spx + (Gl_cos[this.thrustDir] * 10.0), spy + (Gl_sin[this.thrustDir] * 10.0));
	ctx.stroke();
}

function ship()
{
	this.thrustDir = 90; // Thrust starts off downwards
	
	this.positionX = 100.0;
	this.positionY = 75.0;
	
	this.velocityX = 0.0;
	this.velocityY = 0.0;
		
	this.accel = 0.15;

	this.particlesystem = new particlesystem();
	
	this.update = ship_update;
	this.draw = ship_draw;
	this.reset = ship_reset;
}

